#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/12/28 16:22
# @Author  : Andrewq
# @Site    : nope
# @File    : studyHistoryManager.py
# @Software: PyCharm

from flask import current_app, g
from sqlalchemy import or_

from ..controller.studyHistoryController import studyHistoryController
from ..models import db
from ..models.UserCollectModel import UserCollect
from ..utils import commons
from ..utils.response_code import RET


class studyHistoryManager(studyHistoryController):

    @classmethod
    def add_history(cls, **kwargs):
        return cls.add(**kwargs)

    @classmethod
    def delete_history(cls, **kwargs):
        kwargs['mode'] = 'single'
        return cls.delete(**kwargs)

    @classmethod
    def delete_history_list(cls, **kwargs):
        kwargs['mode'] = 'list'
        return cls.delete(**kwargs)

    @classmethod
    def get_history_list(cls, **kwargs):
        return cls.get_list(**kwargs)

    @classmethod
    def get_history_info_by_tags(cls, **kwargs):
        tag_name = kwargs.get('tagname')
        user_id = kwargs.get('userID') if kwargs.get("userID") else g.user.user_id
        if tag_name == '资料标题':
            args = {
                'userID': user_id,
                'preStudyName': kwargs.get('keyword')
            }
        elif tag_name == '时间区间':
            args = {
                'userID': user_id,
                'timeZone': kwargs.get('keyword')
            }
        return cls.get_list(**args)
